export function setToken(tokenKey, token) {
  return localStorage.setItem(tokenKey, token);
}
export function getToken(tokenKey) {
  return localStorage.getItem(tokenKey)
}
export function removeToken(tokenKey) {
  return localStorage.removeItem(tokenKey)
}

// 根据传入的长度生成包含字母和数字的随机字符串
export function generateRandomAlphaNumericString(length) {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
}

// 转化数据库里的时间为xx月xx日xx时的格式
export function formateDate(time) {
  // 创建 Date 对象
  const date = new Date(time);
  // 获取月、日、小时
  const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 注意月份是从0开始计数的，所以要加1
  const day = date.getDate().toString().padStart(2, '0');
  const hours = date.getUTCHours().toString().padStart(2, '0');

  const formattedTime = `${month}月${day}日${hours}时`;

  return formattedTime
}